package com.greensam.pixelengine.websocket.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 消息推送具体事件码
 *
 * @author Ma Chengrui
 * @since 2025/10/10 16:38
 */
@Getter
@AllArgsConstructor
public enum MessageCode {

    CONNECT("CONNECT", "连接成功"),
    DISCONNECT("DISCONNECT", "断开连接"),

    ENTER_EDIT("ENTER_EDIT", "进入编辑状态"),
    EDIT_ACTION("EDIT_ACTION", "执行编辑操作"),
    EXIT_EDIT("EXIT_EDIT", "退出编辑状态"),

    ERROR("ERROR", "发送错误"),

    ;

    private final String code;
    private final String desc;

    public static MessageCode fromCode(String type) {
        return Arrays.stream(values())
                .filter(c -> c.getCode().equals(type))
                .findFirst()
                .orElseThrow(IllegalArgumentException::new);
    }
}
